<?php

declare(strict_types=1);

use Hyperf\ConfigCenter\Mode;
use Hyperf\ConfigNacos\Constants;
use Hyperf\ConfigNacos\NacosDriver;

use function Hyperf\Support\env;

$app_name = env('APP_NAME', 'skeleton');

return [
    'enable' => (bool) env('CONFIG_CENTER_ENABLE', true),
    'driver' => env('CONFIG_CENTER_DRIVER', 'nacos'),
    'mode' => env('CONFIG_CENTER_MODE', Mode::PROCESS), // 覆盖配置
    'drivers' => [
        'nacos' => [
            'driver' => NacosDriver::class,
            'merge_mode' => Constants::CONFIG_MERGE_OVERWRITE,
            'interval' => 3,
            'default_key' => 'nacos_config',
            'listener_config' => [
                // 默认配置 config('nacos_config') 读取结果
                'nacos_config' => [
                    'tenant' => env('NACOS_NAMESPACE', 'public'), // 命名空间
                    'data_id' => "{$app_name}-config", // Data ID 示例 common-service-dev
                    'group' => env('NACOS_GROUP', 'DEFAULT_GROUP'), // Group
                    'type' => 'json',
                ],
            ],
            'client' => [
                // 'uri' => '',
                'host' => env('NACOS_HOST', '127.0.0.1'),
                'port' => env('NACOS_PORT', 8848),
                'username' => env('NACOS_USERNAME', null),
                'password' => env('NACOS_PASSWORD', null),
                'guzzle' => [
                    'config' => null,
                ],
                // Only support for nacos v2.
                'grpc' => [
                    'enable' => true,
                    'heartbeat' => 10,
                ],
            ],
        ],
    ],
];
